import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
Vue.use(ElementUI)

axios.defaults.baseURL = 'http://127.0.0.1:8000/'
Vue.prototype.$axios = axios

axios.interceptors.request.use(res =>{
  console.log(res)
  res.headers.token = localStorage.getItem('token')
  return res
})

axios.interceptors.response.use(res=>{
  console.log(res)
  if(res.data.code == 401){
    alert(res.data.msg)
    router.push('/')
  }
  return res
})

new Vue({
  router,
  store,
  render: function (h) { return h(App) }
}).$mount('#app')
